package com.clear.honghefinance.biz.modules.system.role.job;

import com.clear.honghefinance.biz.modules.system.role.service.ISysRoleService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class SysJobService {

    @Resource
    private ISysRoleService sysRoleService;


    /**
     * 将所有角色绑定的菜单列表设置到缓存中（Bean模式）
     */
    @XxlJob("setSysRoleBindMenuCacheJobHandler")
    public ReturnT<String> setSysRoleBindMenuCacheJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, setSysRoleBindMenuCacheJobHandler -> begin");

        try {
            XxlJobHelper.log("更新所有角色绑定的菜单列表设置到缓存中...");
            sysRoleService.setSysRoleBindMenuCache();
            XxlJobHelper.log("将所有角色绑定的菜单列表设置到缓存成功...");
        } catch (Exception e) {
            XxlJobHelper.log("将所有角色绑定的菜单列表设置到缓存中失败...");
            return ReturnT.FAIL;
        }
        return ReturnT.SUCCESS;
    }

    /**
     * 将所有角色绑定的资源列表设置到缓存中（Bean模式）
     */
    @XxlJob("setSysRoleBindResourceCacheJobHandler")
    public ReturnT<String> setSysRoleBindResourceCacheJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, setSysRoleBindResourceCacheJobHandler -> begin");

        try {
            XxlJobHelper.log("更新所有角色绑定的资源列表设置到缓存中...");
            sysRoleService.setSysRoleBindResourceCache();
            XxlJobHelper.log("将所有角色绑定的资源列表设置到缓存成功...");
        } catch (Exception e) {
            XxlJobHelper.log("将所有角色绑定的资源列表设置到缓存中失败...");
            return ReturnT.FAIL;
        }
        return ReturnT.SUCCESS;
    }
}
